package com.ctrip.corp.obt.shard.filter;


import com.ctrip.corp.obt.shard.context.PageContext;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author marco.zheng
 * @version 1.0
 * @date 2021/05/06
 * @desc Page filter
 * @see
 * @since 1.0
 */
@Slf4j
@WebFilter(filterName = "pageFilter", urlPatterns = "/*")
public class PageFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        if (PageContext.hasPageParam()) {
            PageContext.setPage(PageContext.buildPage());
        }
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
